package com.ruoyi.news.service.impl;

import java.math.BigDecimal;
import java.util.*;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SerialNo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.common.utils.wxUtils.SendWxMapMsg;
import com.ruoyi.common.utils.wxUtils.TemplateData;
import com.ruoyi.common.utils.wxUtils.Wxmp;
import com.ruoyi.news.domain.*;
import com.ruoyi.news.mapper.XcxOrderMainMapper;
import com.ruoyi.news.service.*;
import com.ruoyi.news.utils.WxRedisAccessToken;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 订单主Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-24
 */
@Service
public class XcxOrderMainServiceImpl implements IXcxOrderMainService
{
    @Autowired
    private XcxOrderMainMapper xcxOrderMainMapper;

    @Autowired
    private IXcxOrderStateService xcxOrderStateService;

    @Autowired
    private IXcxWalletInfoService xcxWalletInfoService;

    @Autowired
    private WxRedisAccessToken wxRedisAccessToken;

    @Autowired
    private ISysUserService sysUserService;


    /**
     * 查询订单主
     * 
     * @param id 订单主主键
     * @return 订单主
     */
    @Override
    public XcxOrderMain selectXcxOrderMainById(String id)
    {
        return xcxOrderMainMapper.selectXcxOrderMainById(id);
    }

    /**
     * 查询订单主列表
     * 
     * @param xcxOrderMain 订单主
     * @return 订单主
     */
    @Override
    public List<XcxOrderMain> selectXcxOrderMainList(XcxOrderMain xcxOrderMain)
    {
        return xcxOrderMainMapper.selectXcxOrderMainList(xcxOrderMain);
    }

    @Override
    public List<XcxOrderMain> selectListMyOrder(XcxOrderMain xcxOrderMain) {
        return xcxOrderMainMapper.selectListMyOrder(xcxOrderMain);
    }

    /**
     * 新增订单主
     * 
     * @param xcxOrderMain 订单主
     * @return 结果
     */
    @Override
    public XcxOrderMain insertXcxOrderMain(XcxOrderMain xcxOrderMain, SysUser sysUser)
    {
        String orderId = SerialNo.generateOrderNumber();
        xcxOrderMain.setCreateTime(DateUtils.getNowDate());
        xcxOrderMain.setCreateBy(sysUser.getUserId()+"");
        xcxOrderMain.setId(IdUtils.fastSimpleUUID());
        xcxOrderMain.setOrderId(orderId);

        //是否指派接单
        //未指定

            if (StringUtils.isEmpty(xcxOrderMain.getAppointPeople())) {
                xcxOrderMain.setState("1");
                xcxOrderMainMapper.insertXcxOrderMain(xcxOrderMain);
                XcxOrderState xcxOrderState = new XcxOrderState();
                xcxOrderState.setOrderId( orderId );
                xcxOrderState.setTime(new Date());
                xcxOrderState.setState("11");
                xcxOrderState.setType("1");
                xcxOrderState.setTakeUser(sysUser.getUserId() + "");
                xcxOrderState.setId(IdUtils.fastSimpleUUID());
                xcxOrderStateService.insertXcxOrderState(xcxOrderState);
                return xcxOrderMain;

            } else {
                xcxOrderMain.setTakeUser(xcxOrderMain.getAppointPeople());
                xcxOrderMain.setState("3");
                xcxOrderMainMapper.insertXcxOrderMain(xcxOrderMain);
                //指定
                //接方
                XcxOrderState xcxOrderState = new XcxOrderState();
                xcxOrderState.setOrderId(orderId);
                xcxOrderState.setTime(new Date());
                xcxOrderState.setState("12");
                xcxOrderState.setType("1");
                xcxOrderState.setTakeUser(sysUser.getUserId() + "");
                xcxOrderState.setId(IdUtils.fastSimpleUUID());
                xcxOrderStateService.insertXcxOrderState(xcxOrderState);
                //发方
                XcxOrderState xcxOrderStateSend = new XcxOrderState();
                xcxOrderStateSend.setOrderId(orderId);
                xcxOrderStateSend.setTime(new Date());
                xcxOrderStateSend.setState("1");
                xcxOrderStateSend.setType("2");
                xcxOrderStateSend.setTakeUser(xcxOrderMain.getAppointPeople());
                xcxOrderStateSend.setId(IdUtils.fastSimpleUUID());
                xcxOrderStateService.insertXcxOrderState(xcxOrderStateSend);
                return xcxOrderMain;

            }
    }

    /**
     * 修改订单主
     * 
     * @param xcxOrderMain 订单主
     * @return 结果
     */
    @Override
    public int updateXcxOrderMain(XcxOrderMain xcxOrderMain)
    {
        xcxOrderMain.setUpdateTime(DateUtils.getNowDate());
        return xcxOrderMainMapper.updateXcxOrderMain(xcxOrderMain);
    }

    /**
     * 批量删除订单主
     * 
     * @param ids 需要删除的订单主主键
     * @return 结果
     */
    @Override
    public int deleteXcxOrderMainByIds(String[] ids)
    {
        return xcxOrderMainMapper.deleteXcxOrderMainByIds(ids);
    }

    /**
     * 删除订单主信息
     * 
     * @param id 订单主主键
     * @return 结果
     */
    @Override
    public int deleteXcxOrderMainById(String id)
    {
        return xcxOrderMainMapper.deleteXcxOrderMainById(id);
    }

    @Override
    public int takeOrder(XcxOrderMain xcxOrderMain) {
        /* 判断不能接自己单 */
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        if(temp.getCreateBy().equals(xcxOrderMain.getTakeUser())){
            return  0;
        }
        /* 判断不能被同一个人二次接单 */
        XcxOrderState query = new XcxOrderState();
        query.setTakeUser(xcxOrderMain.getTakeUser());
        query.setOrderId(xcxOrderMain.getOrderId());
        XcxOrderState stateTmep = xcxOrderStateService.selectXcxOrderByVo(query);
        if(null != stateTmep){
            return  0;
        }
        //新增订单状态
        XcxOrderState xcxOrderState = new XcxOrderState();
        xcxOrderState.setOrderId(xcxOrderMain.getOrderId());
        xcxOrderState.setTime(new Date());
        xcxOrderState.setState("1");
        xcxOrderState.setType("2");
        xcxOrderState.setTakeUser(xcxOrderMain.getTakeUser());
        xcxOrderState.setId(IdUtils.fastSimpleUUID());
        xcxOrderStateService.insertXcxOrderState(xcxOrderState);

        //修改发方状态
        XcxOrderState sendState = new XcxOrderState();
        sendState.setTakeUser(temp.getCreateBy());
        sendState.setOrderId(temp.getOrderId());
        XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
        sendRes.setState("12");
        xcxOrderStateService.updateXcxOrderState(sendRes);
        //sql 修改状态为3 - 已接单

        //通知发单方 订单已被接取
        SysUser takeUser = sysUserService.selectUserById(Long.parseLong(xcxOrderMain.getTakeUser()));
        SysUser sendUser = sysUserService.selectUserById(Long.parseLong(temp.getCreateBy()));

        String openid = sendUser.getOpenId();
        //拼接推送的模版
        Wxmp wxmp = new Wxmp();
        //用户的openId
        wxmp.setTouser(openid);
        wxmp.setTemplate_id( SendWxMapMsg.takeOrder );

        Map<String, TemplateData> data = new HashMap<>();
        data.put("thing2", new TemplateData(temp.getTitle()));
        data.put("character_string4", new TemplateData(temp.getOrderId()));
        data.put("thing10", new TemplateData(takeUser.getNickName()));
        data.put("time11", new TemplateData(DateUtils.getDate()));
        wxmp.setData(data);

        SendWxMapMsg pushBizService = new SendWxMapMsg();
        pushBizService.pushOneUser(wxmp,wxRedisAccessToken.getWxAccessToken());

        return  xcxOrderMainMapper.takeOrder(xcxOrderMain);
    }


    //接放 --  撤销订单
    @Override
    public int closeOrder(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        //修改接单方状态
        XcxOrderState takeState = new XcxOrderState();
        takeState.setTakeUser(temp.getTakeUser());
        takeState.setOrderId(temp.getOrderId());
        XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
        xcxOrderState.setState("2");
        int flag =  xcxOrderStateService.updateXcxOrderState(xcxOrderState);
        if(flag>0){
            XcxOrderState sendState = new XcxOrderState();
            sendState.setTakeUser(temp.getCreateBy());
            sendState.setOrderId(temp.getOrderId());
            XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
            sendRes.setState("13");
            return xcxOrderStateService.updateXcxOrderState(sendRes);
        }
        return 0;
    }

    @Override
    public int successBack(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        //修改主订单状态
        temp.setState("2");
        xcxOrderMainMapper.updateXcxOrderMain(temp);
        //修改接单方状态
        XcxOrderState takeState = new XcxOrderState();
        takeState.setTakeUser(temp.getTakeUser());
        takeState.setOrderId(temp.getOrderId());
        XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
        xcxOrderState.setState("7");
        int flag =  xcxOrderStateService.updateXcxOrderState(xcxOrderState);
        if(flag>0){
            XcxOrderState sendState = new XcxOrderState();
            sendState.setTakeUser(temp.getCreateBy());
            sendState.setOrderId(temp.getOrderId());
            XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
            sendRes.setState("11");
            return xcxOrderStateService.updateXcxOrderState(sendRes);
        }
        return 0;
    }

    @Override
    public int noBack(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        xcxOrderMainMapper.updateXcxOrderMain(temp);
        //修改接单方状态
        XcxOrderState takeState = new XcxOrderState();
        takeState.setTakeUser(temp.getTakeUser());
        takeState.setOrderId(temp.getOrderId());
        XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
        xcxOrderState.setState("1");
        int flag =  xcxOrderStateService.updateXcxOrderState(xcxOrderState);
        if(flag>0){
            XcxOrderState sendState = new XcxOrderState();
            sendState.setTakeUser(temp.getCreateBy());
            sendState.setOrderId(temp.getOrderId());
            XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
            sendRes.setState("15");
            return xcxOrderStateService.updateXcxOrderState(sendRes);
        }
        return 0;
    }

    @Override
    public int canceBackOrder(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        //修改接单方状态
        XcxOrderState takeState = new XcxOrderState();
        takeState.setTakeUser(temp.getTakeUser());
        takeState.setOrderId(temp.getOrderId());
        XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
        xcxOrderState.setState("1");
        int flag =  xcxOrderStateService.updateXcxOrderState(xcxOrderState);
        if(flag>0){
            XcxOrderState sendState = new XcxOrderState();
            sendState.setTakeUser(temp.getCreateBy());
            sendState.setOrderId(temp.getOrderId());
            XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
            sendRes.setState("12");
            return xcxOrderStateService.updateXcxOrderState(sendRes);
        }
        return 0;
    }

    @Override
    public int cancelOrder(XcxOrderMain xcxOrderMain, String raid) {
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        if(temp.getState().equals("2")){
            temp.setState("-99");
            int mainFlag = xcxOrderMainMapper.updateXcxOrderMain(temp);
            if(mainFlag > 0){
                XcxOrderState sendState = new XcxOrderState();
                sendState.setTakeUser(temp.getCreateBy());
                sendState.setOrderId(temp.getOrderId());
                XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
                sendRes.setState("18");

                 int res = xcxOrderStateService.updateXcxOrderState(sendRes);
                 if(res > 0 ){ // 平台扣除佣金
                     XcxWalletInfo xcxWalletInfo = new XcxWalletInfo();
                     xcxWalletInfo.setId(IdUtils.fastSimpleUUID());
                     xcxWalletInfo.setUserId(temp.getCreateBy());
                     xcxWalletInfo.setType("3");
                     xcxWalletInfo.setOrderMain( temp );
                     xcxWalletInfo.setRaid(raid);
                     xcxWalletInfo.setBid(temp.getOrderId());
                     xcxWalletInfoService.insertXcxWalletInfo(xcxWalletInfo,null);
                 }
                return res;
            }
        }
        return 0;
    }

    @Override
    public int updateMoney(XcxOrderMain xcxOrderMain) {
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        String oldPrice = temp.getPrice();
        temp.setPrice(xcxOrderMain.getPrice());
        int res = xcxOrderMainMapper.updateXcxOrderMain(temp);
        if(res > 0){ // 重新计算 锁定金额
            XcxWalletInfo xcxWalletInfo = new XcxWalletInfo();
            xcxWalletInfo.setId(IdUtils.fastSimpleUUID());
            xcxWalletInfo.setUserId(temp.getCreateBy());
            xcxWalletInfo.setType("5");
            xcxWalletInfo.setOrderMain( temp );
            xcxWalletInfo.setNewPrice(new BigDecimal(xcxOrderMain.getPrice()));
            xcxWalletInfo.setOldPrice(new BigDecimal(oldPrice));
            xcxWalletInfo.setBid(temp.getOrderId());
            return xcxWalletInfoService.insertXcxWalletInfo(xcxWalletInfo,null);
        }
        return 0;
    }

    @Override
    public int sendBackOrder(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        //修改接单方状态
        XcxOrderState takeState = new XcxOrderState();
        takeState.setTakeUser(temp.getTakeUser());
        takeState.setOrderId(temp.getOrderId());
        XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
        xcxOrderState.setState("3");
        int flag =  xcxOrderStateService.updateXcxOrderState(xcxOrderState);
        if(flag>0){
            XcxOrderState sendState = new XcxOrderState();
            sendState.setTakeUser(temp.getCreateBy());
            sendState.setOrderId(temp.getOrderId());
            XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
            sendRes.setState("14");
            return xcxOrderStateService.updateXcxOrderState(sendRes);
        }
        return 0;
    }

    @Override
    public int sendCanceBack(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        //修改接单方状态
        XcxOrderState takeState = new XcxOrderState();
        takeState.setTakeUser(temp.getTakeUser());
        takeState.setOrderId(temp.getOrderId());
        XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
        xcxOrderState.setState("2");
        int flag =  xcxOrderStateService.updateXcxOrderState(xcxOrderState);
        if(flag>0){
            XcxOrderState sendState = new XcxOrderState();
            sendState.setTakeUser(temp.getCreateBy());
            sendState.setOrderId(temp.getOrderId());
            XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
            sendRes.setState("12");
            return xcxOrderStateService.updateXcxOrderState(sendRes);
        }
        return 0;
    }

    @Override
    public int successSendBack(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        //修改主订单状态
        temp.setTakeUser(null);
        temp.setState("2");
        xcxOrderMainMapper.updateXcxOrderMain(temp);
        //修改接单方状态
        XcxOrderState takeState = new XcxOrderState();
        takeState.setTakeUser(temp.getTakeUser());
        takeState.setOrderId(temp.getOrderId());
        XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
        xcxOrderState.setState("7");
        int flag =  xcxOrderStateService.updateXcxOrderState(xcxOrderState);
        if(flag>0){
            XcxOrderState sendState = new XcxOrderState();
            sendState.setTakeUser(temp.getCreateBy());
            sendState.setOrderId(temp.getOrderId());
            XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
            sendRes.setState("11");
            return xcxOrderStateService.updateXcxOrderState(sendRes);
        }
        return 0;
    }

    @Override
    public int noSendBack(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        xcxOrderMainMapper.updateXcxOrderMain(temp);
        //修改接单方状态
        XcxOrderState takeState = new XcxOrderState();
        takeState.setTakeUser(temp.getTakeUser());
        takeState.setOrderId(temp.getOrderId());
        XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
        xcxOrderState.setState("5");
        int flag =  xcxOrderStateService.updateXcxOrderState(xcxOrderState);
        if(flag>0){
            XcxOrderState sendState = new XcxOrderState();
            sendState.setTakeUser(temp.getCreateBy());
            sendState.setOrderId(temp.getOrderId());
            XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
            sendRes.setState("12");
            return xcxOrderStateService.updateXcxOrderState(sendRes);
        }
        return 0;
    }

    @Override
    public int successOrder(XcxOrderMain xcxOrderMain) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        temp.setState("4");
        temp.setSuccessMsg(xcxOrderMain.getSuccessMsg());
        int mainFlag = xcxOrderMainMapper.updateXcxOrderMain(temp);
        if(mainFlag > 0) {
            //修改接单方状态
            XcxOrderState takeState = new XcxOrderState();
            takeState.setTakeUser(temp.getTakeUser());
            takeState.setOrderId(temp.getOrderId());
            XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
            xcxOrderState.setState("4");
            int flag = xcxOrderStateService.updateXcxOrderState(xcxOrderState);
            if (flag > 0) {
                XcxOrderState sendState = new XcxOrderState();
                sendState.setTakeUser(temp.getCreateBy());
                sendState.setOrderId(temp.getOrderId());
                XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
                sendRes.setState("16");
                return xcxOrderStateService.updateXcxOrderState(sendRes);
            }
        }
        return 0;
    }

    @Override
    public int confSuccess(XcxOrderMain xcxOrderMain,String raid) {
        //主订单信息
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        temp.setState("4");
        int mainFlag = xcxOrderMainMapper.updateXcxOrderMain(temp);
        if(mainFlag > 0) {
            //修改接单方状态
            XcxOrderState takeState = new XcxOrderState();
            takeState.setTakeUser(temp.getTakeUser());
            takeState.setOrderId(temp.getOrderId());
            XcxOrderState xcxOrderState = xcxOrderStateService.selectXcxOrderByVo(takeState);
            xcxOrderState.setState("6");
            int flag = xcxOrderStateService.updateXcxOrderState(xcxOrderState);
            if (flag > 0) {
                XcxOrderState sendState = new XcxOrderState();
                sendState.setTakeUser(temp.getCreateBy());
                sendState.setOrderId(temp.getOrderId());
                XcxOrderState sendRes = xcxOrderStateService.selectXcxOrderByVo(sendState);
                sendRes.setState("17");
                int res = xcxOrderStateService.updateXcxOrderState(sendRes);
                if(res > 0){ //平台扣除佣金
                    XcxWalletInfo xcxWalletInfo = new XcxWalletInfo();
                    xcxWalletInfo.setId(IdUtils.fastSimpleUUID());
                    xcxWalletInfo.setUserId(temp.getTakeUser());
                    xcxWalletInfo.setType("4");
                    xcxWalletInfo.setOrderMain( temp );
                    xcxWalletInfo.setRaid(raid);
                    xcxWalletInfo.setBid(temp.getOrderId());
                    xcxWalletInfoService.insertXcxWalletInfo(xcxWalletInfo,null);

                    //通知发单方 订单已被接取
                    SysUser takeUser = sysUserService.selectUserById(Long.parseLong(xcxOrderMain.getTakeUser()));
                    SysUser sendUser = sysUserService.selectUserById(Long.parseLong(temp.getCreateBy()));

                    String openid = sendUser.getOpenId();
                    //拼接推送的模版
                    Wxmp wxmp = new Wxmp();
                    //用户的openId
                    wxmp.setTouser(openid);
                    wxmp.setTemplate_id( SendWxMapMsg.seccussOrder );

                    Map<String, TemplateData> data = new HashMap<>();
                    data.put("thing2", new TemplateData(temp.getTitle()));
                    data.put("character_string4", new TemplateData(temp.getOrderId()));
                    data.put("thing10", new TemplateData(takeUser.getNickName()));
                    data.put("time11", new TemplateData(DateUtils.getDate()));
                    wxmp.setData(data);

                    SendWxMapMsg pushBizService = new SendWxMapMsg();
                    pushBizService.pushOneUser(wxmp,wxRedisAccessToken.getWxAccessToken());
                }
            }
        }
        return 0;
    }

    @Override
    public int uploadTakeImg(XcxOrderMain xcxOrderMain) {

        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        temp.setTakeMsg(xcxOrderMain.getTakeMsg());
        return xcxOrderMainMapper.updateXcxOrderMain(temp);
    }

    @Override
    public int deleteOrder(XcxOrderMain xcxOrderMain) {

        /*
        * 发方钱退还
        * */
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        if(temp.getState().equals("1")){
            temp.setState("-99");
            int flag = xcxOrderMainMapper.updateXcxOrderMain(temp);
            if( flag > 0 ){

            }
        }
        return 0;
    }

    @Override
    public int arbitrationOrder(XcxOrderMain xcxOrderMain) {
        XcxOrderMain temp = xcxOrderMainMapper.selectXcxOrderMainByOrderId(xcxOrderMain.getOrderId());
        /*
        * 1.处理发方所得
        * 2.处理接方所得
        * 3.处理订单状态
        * */
        if(StringUtils.isNotEmpty(xcxOrderMain.getMoneySend())){

        }

        if(StringUtils.isNotEmpty(xcxOrderMain.getMoneyTake())){

        }

        if(StringUtils.isNotEmpty(xcxOrderMain.getState())){

        }

        return 0;
    }


    @Autowired
    private IXcxGoodsOrderService xcxGoodsOrderService;

    @Override
    public int deleteGoodsOrder(XcxGoodsOrder xcxGoodsOrder) {
        XcxGoodsOrder temp = xcxGoodsOrderService.selectXcxGoodsOrderById(xcxGoodsOrder.getId());
        temp.setState("-99");
        int flag =  xcxGoodsOrderService.updateXcxGoodsOrder(temp);
        if(flag > 0){
            XcxWalletInfo xcxWalletInfo = new XcxWalletInfo();
            xcxWalletInfo.setGoodsOrder(temp);
            xcxWalletInfo.setId(IdUtils.fastSimpleUUID());
            xcxWalletInfo.setUserId(temp.getCreateBy());
            xcxWalletInfo.setType("7");
            xcxWalletInfo.setBid(temp.getId());
            return xcxWalletInfoService.insertGoodsXcxWalletInfo(xcxWalletInfo,null);
        }
        return 0;
    }

    @Override
    public int successGoods(XcxGoodsOrder xcxGoodsOrder) {
        XcxGoodsOrder temp = xcxGoodsOrderService.selectXcxGoodsOrderById(xcxGoodsOrder.getId());
        temp.setState("3");
        return xcxGoodsOrderService.updateXcxGoodsOrder(temp);
    }

    @Override
    public int backGoods(XcxGoodsOrder xcxGoodsOrder) {
        XcxGoodsOrder temp = xcxGoodsOrderService.selectXcxGoodsOrderById(xcxGoodsOrder.getId());
        temp.setState("5");
        return xcxGoodsOrderService.updateXcxGoodsOrder(temp);
    }

    @Override
    public int confSuccess(XcxGoodsOrder xcxGoodsOrder) {
        XcxGoodsOrder temp = xcxGoodsOrderService.selectXcxGoodsOrderById(xcxGoodsOrder.getId());
        temp.setState("4");
        return xcxGoodsOrderService.updateXcxGoodsOrder(temp);
    }

    @Override
    public int successBackGoods(XcxGoodsOrder xcxGoodsOrder) {
        XcxGoodsOrder temp = xcxGoodsOrderService.selectXcxGoodsOrderById(xcxGoodsOrder.getId());
        temp.setState("6");
        int flag =  xcxGoodsOrderService.updateXcxGoodsOrder(temp);
        if(flag > 0){
            XcxWalletInfo xcxWalletInfo = new XcxWalletInfo();
            xcxWalletInfo.setGoodsOrder(temp);
            xcxWalletInfo.setId(IdUtils.fastSimpleUUID());
            xcxWalletInfo.setUserId(temp.getCreateBy());
            xcxWalletInfo.setType("8");
            xcxWalletInfo.setBid(temp.getId());
            return xcxWalletInfoService.insertGoodsXcxWalletInfo(xcxWalletInfo,null);
        }
        return 0;
    }

    @Override
    public int noBackGoods(XcxGoodsOrder xcxGoodsOrder) {
        XcxGoodsOrder temp = xcxGoodsOrderService.selectXcxGoodsOrderById(xcxGoodsOrder.getId());
        temp.setState("7");
        return xcxGoodsOrderService.updateXcxGoodsOrder(temp);
    }
}
